package hiepst.solution;

/**
 * Problem Statement
 * <p>
 * Sometimes when computer programs have a limited number of colors to use, they
 * use a technique called dithering. Dithering is when you use a pattern made up
 * of different colors such that when the colors are viewed together, they
 * appear like another color. For example, you can use a checkerboard pattern of
 * black and white pixels to achieve the illusion of gray. You are writing a
 * program to determine how much of the screen is covered by a certain dithered
 * color. Given a computer screen where each pixel has a certain color, and a
 * list of all the solid colors that make up the dithered color, return the
 * number of pixels on the screen that are used to make up the dithered color.
 * Each pixel will be represented by a character in screen. Each character in
 * screen and in dithered will be an uppercase letter ('A'-'Z') representing a
 * color. Assume that any pixel which is a color contained in dithered is part
 * of the dithered color.
 * </p>
 * 
 * Definition Class:<br>
 * ImageDithering<br>
 * Method: count<br>
 * Parameters: String, String[]<br>
 * Returns: int<br>
 * Method signature: int count(String dithered, String[] screen)<br>
 * (be sure your method is public)<br>
 * 
 * Limits<br>
 * Time limit (s): 2.000<br>
 * Memory limit (MB): 64<br>
 * 
 * Constraints<br>
 * - dithered will contain between 2 and 26 upper case letters ('A'-'Z'),
 * inclusive.<br>
 * - There will be no repeated characters in dithered.<br>
 * - screen will have between 1 and 50 elements, inclusive.<br>
 * - Each element of screen will contain between 1 and 50 upper case letters
 * ('A'-'Z'), inclusive.<br>
 * - All elements of screen will contain the same number of characters.<br>
 * 
 * Examples<br>
 * 0) "BW"<br>
 * {"AAAAAAAA",<br>
 * "ABWBWBWA",<br>
 * "AWBWBWBA",<br>
 * "ABWBWBWA",<br>
 * "AWBWBWBA",<br>
 * "AAAAAAAA"}<br>
 * Returns: 24<br>
 * <p>
 * Here, our dithered color could consist of black (B) and white (W) pixels,
 * composing a shade of gray. In the picture, there is a dithered gray square
 * surrounded by another color (A).
 * </p>
 * 
 * 1) "BW"<br>
 * {"BBBBBBBB",<br>
 * "BBWBWBWB",<br>
 * "BWBWBWBB",<br>
 * "BBWBWBWB",<br>
 * "BWBWBWBB",<br>
 * "BBBBBBBB"}<br>
 * Returns: 48<br>
 * <p>
 * Here is the same picture, but with the outer color replaced with black
 * pixels. Although in reality, the outer pixels do not form a dithered color,
 * your algorithm should still assume they are part of the dithered pattern.
 * </p>
 * 
 * 2) "ACEGIKMOQSUWY"<br>
 * {"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX",<br>
 * "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX",<br>
 * "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX",<br>
 * "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX",<br>
 * "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX",<br>
 * "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWX"}<br>
 * Returns: 150<br>
 * A picture of vertical stripes, every other stripe is considered part of the
 * dithered color.<br>
 * 
 * 3) "CA"<br>
 * {"BBBBBBB",<br>
 * "BBBBBBB",<br>
 * "BBBBBBB"}<br>
 * Returns: 0<br>
 * The dithered color is not present.<br>
 * 
 * 4) "DCBA"<br>
 * {"ACBD"}<br>
 * Returns: 4<br>
 * The order of the colors doesn't matter.<br>
 * 
 * <p>
 * This problem statement is the exclusive and proprietary property of TopCoder,
 * Inc. Any unauthorized use or reproduction of this information without the
 * prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003,
 * TopCoder, Inc. All rights reserved.
 * </p>
 * 
 * 
 * @author Hiep.Hong
 * 
 */
public class SRM145Div2_ImageDithering {

	public int count(String dithered, String[] screen) {
		int count = 0;

		for (int i = 0; i < screen.length; i++) {
			String row = screen[i];

			for (int j = 0; j < row.length(); j++) {
				if (dithered.contains(row.charAt(j) + "")) {
					count++;
				}
			}
		}

		return count;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SRM145Div2_ImageDithering imageDithering = new SRM145Div2_ImageDithering();
		int count = imageDithering.count("BW", new String[] { "AAAAAAAA",
				"ABWBWBWA", "AWBWBWBA", "ABWBWBWA", "AWBWBWBA", "AAAAAAAA" });
		System.out.println("count = " + count);

		count = imageDithering.count("BW", new String[] { "BBBBBBBB",
				"BBWBWBWB", "BWBWBWBB", "BBWBWBWB", "BWBWBWBB", "BBBBBBBB" });
		System.out.println("count = " + count);
	}
}
